<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    request.setAttribute("path", path);
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <base href="<%=basePath%>">
    <title>入库审核记录</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css"/>
    <script type="text/javascript" src="${pageContext.request.contextPath}/layui/layui.js"></script>


</head>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>入库审核信息</legend>
</fieldset>

<%--  搜索行--%>
<div class="demoTable">
    图书名称：
    <div class="layui-inline">
        <input class="layui-input" placeholder="请输入编号" name="id" id="id" autocomplete="off">
    </div>
    <button class="layui-btn" data-type="reload" id="search">搜索</button>
</div>
<%--头部栏--%>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container" >
        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
        <button class="layui-btn layui-btn-sm" lay-event="delCheck">批量删除</button>
    </div>
</script>
<table class="layui-table" id="test" lay-filter="test"></table>

<%--右侧操作栏--%>
<script type="text/html" id="barDemo">
    <a  class="layui-btn layui-btn-warm layui-btn-sm" lay-event="edit">查看详情</a>
</script>
</body>
<script type="text/javascript">
    layui.use(['table','form','jquery','layer'], function() {
        var table = layui.table;
        var form = layui.form;
        var $ = layui.jquery;
        var layer = layui.layer;
        $(function () {
            //当页面加载完成后执行的事件
            showTable();
            showSq();
        });

        //加载计划采购表格
        function showTable(){
            table.render({
                elem: '#test'
                ,url:'${pageContext.request.contextPath}/proln/getAllProln'
                ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
                ,totalRow: true
                ,title: '入库信息'
                ,cols: [[
                    {type: 'checkbox', fixed: 'left'}
                    ,{field:'id', title:'ID', edit: 'text'}
                    ,{field: 'rdate',title:'入库时间',edit: 'date'}
                    ,{field: 'jsr',title:'入库人'}
                    ,{field: 'staffName',title:'经手人'}
                    //,{field:'bookname', title:'图书名称', unresize: true, sort: true}
                    ,{field:'count', title:'数量',sort: true}
                    ,{field:'sum_price', title:'总金额',sort: true }
                    ,{fixed: 'right', title:'操作', toolbar: '#barDemo',width:110}
                ]]
                ,page: true
                ,limit:5
                ,limits:[3,5,10,15]
                ,text:{
                    none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
                }
            });
        }

        //监听复选框选中
        table.on('tool(test)', function(obj){
            var data=obj.data;
            if(obj.event==='requestBook'){
                layer.open({
                    type: 1,
                    content: '<table class="layui-hide" id="detailInfo" lay-filter="detailInfo"></table>', //这里content是一个普通的String
                    success:function () {
                        detailInfo(data.outnumber);
                    }
                });
            }
        });

        //加载查看详情表格
        function showSq(){
            table.render({
                elem: '#sqDemo'
                ,url:'${pageContext.request.contextPath}/proln/getAllProln'
                //,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
                ,totalRow: true
                ,title: '查看详情信息'
                ,cols: [[
                    {type: 'checkbox', fixed: 'left'}
                    ,{field:'id', title:'ID',totalRowText: '合计', fixed: 'left'}
                    ,{field:'bookname', title:'图书名称', unresize: true, sort: true}
                    ,{field:'count', title:'数量',sort: true, totalRow: true}
                    ,{field:'sum_price', title:'总金额',sort: true, totalRow: true}
                    ,{field: 'rdate',title:'入库时间',edit: 'date'}
                    ,{field: 'jsr',title:'入库人'}
                    ,{field: 'staffName',title:'经手人'}
                ]]
                //,page: true
               // ,limit:5
               // ,limits:[3,5,10,15]
                ,text:{
                    none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
                }
            });
        }

        //搜索
        $("#search").click(function () {
            //执行重载
            table.reload('test',{
                page:{
                    curr:1//重新从第一页开始
                }
                ,where:{
                    id:$("#id").val()
                }
            },'data')
        });

        //头工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'getCheckData':
                    var data = checkStatus.data;
                    layer.alert(JSON.stringify(data));
                    break;
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选': '未全选');
                    break;

                //自定义头工具栏右侧图标 - 提示
                case 'LAYTABLE_TIPS':
                    layer.alert('这是工具栏右侧自定义的一个图标按钮');
                    break;
            };
        });

        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            if(obj.event === 'edit'){
                // $("#sqDemo")[0].reset();
                layer.open({
                    type: 2 //此处以iframe举例
                    ,title: '入库详情'
                    ,maxmin: true
                    ,offset: '100px'
                    ,area:['750px','300px']
                    ,content: 'Particulars.jsp'
                });
                //填充选中行数据到指定表单
                form.val('formData', data);
            } else if(obj.event === 'sj'){
                $.get('${pageContext.request.contextPath}/request/updateStatus',{"status":data.status,"id":data.id},function (result){
                    if (result.code == 1 ){
                        showTable();
                        layer.msg(result.msg, {icon: 1});
                    }else{
                        layer.msg(result.msg, {icon: 5});
                    }
                },'json')
            }
        });


    });
</script>
</html>
